import { http } from "@/utils/http";

/** 查询参数 */
export interface ConversationRecordListCommand extends BasePageQuery {
  spoken?: string;
  receivedName?: string;
  groupName?: string;
  roomType?: string;
  answer?: string;
  beginTime?: string;
  endTime?: string;
}

/** 返回结构 */
export interface ConversationRecordPageResponse {
  id: number;
  spoken: string;
  receivedName: string;
  groupName: string;
  roomType: string;
  answer: string;
  createTime: string;
  tokenUse: number;
}

/** 获取会话记录分页列表 */
export function getConversationRecordListApi(
  params: ConversationRecordListCommand
) {
  return http.request<ResponseData<PageDTO<ConversationRecordPageResponse>>>(
    "get",
    "/bot/conversation-record/list",
    {
      params
    }
  );
}

/** 导出会话记录为 Excel */
export const exportConversationRecordExcelApi = (
  params: ConversationRecordListCommand,
  fileName: string
) => {
  return http.download("/bot/conversation-record/excel", fileName, {
    params
  });
};

/** 删除会话记录 */
export const deleteConversationRecordApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>(
    "delete",
    "/bot/conversation-record",
    {
      params: {
        ids: data.toString()
      }
    }
  );
};

/** 添加会话记录 */
export interface AddConversationRecordCommand {
  spoken: string;
  receivedName: string;
  groupName: string;
  roomType: string;
  answer: string;
  tokenUse: number;
}

export const addConversationRecordApi = (
  data: AddConversationRecordCommand
) => {
  return http.request<ResponseData<void>>("post", "/bot/conversation-record", {
    data
  });
};

/** 修改会话记录 */
export interface UpdateConversationRecordCommand
  extends AddConversationRecordCommand {
  id: number;
}

export const updateConversationRecordApi = (
  data: UpdateConversationRecordCommand
) => {
  return http.request<ResponseData<void>>("put", "/bot/conversation-record", {
    data
  });
};

/** 获取单条记录详情 */
export const getConversationRecordInfoApi = (id: number) => {
  return http.request<ResponseData<ConversationRecordPageResponse>>(
    "get",
    `/bot/conversation-record/${id}`
  );
};
